package org.example.cloud.util;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author 宋孟林
 * @description
 * @date: 2025/4/5 7:49
 */
@Data
//此注解属于lombok，让生成的set方法可以支持链式调用，可读性更强 例如 User user = new User().setName("Alice").setAge(25).setId(1);
@Accessors(chain = true)
public class ResultData<T> {
    private String code;
    private String message;
    private T data;
    private long timestamp;

    public ResultData(){
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> ResultData<T> success(T data){
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(ReturnCodeEnum.RC200.getCode());
        resultData.setMessage(ReturnCodeEnum.RC200.getMessage());
        resultData.setData(data);
        return resultData;
    }

    public static <T> ResultData<T> fail(String code, String message){
        ResultData<T> resultData = new ResultData<>();
        resultData.setData(null);
        resultData.setCode(code);
        resultData.setMessage(message);
        return resultData;
    }

}
